package com.example.netty;

import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener {

    private Button lBtLgoin;
    private EditText mEtUser;
    private EditText mEtPassword;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        //找到控件
        lBtLgoin = findViewById(R.id.btn_login);
        mEtUser = findViewById(R.id.et_1);
        mEtPassword = findViewById(R.id.et_2);
        //实现跳转

        lBtLgoin.setOnClickListener(this);
    }

    public void onClick(View v){
        //需要获取输入的用户名和密码
        String username = mEtUser.getText().toString();
        String password = mEtPassword.getText().toString();
        //弹出内容设置
        String ok = "登陆成功！";
        String fail = "登陆失败！";
        Intent intent = null;

        //假设正确的账号和密码为 root 123456
        if (username.equals("root")&&password.equals("123456")){
            //toast 青春版
            Toast.makeText(getApplicationContext(),ok,Toast.LENGTH_SHORT).show();


            //如果正确的话进行跳转
            intent = new Intent(LoginActivity.this,MainActivity.class);
            startActivity(intent);
        }else{
            //失败弹出不正确toast
            //toast 满血版
           Toast toastcenter = Toast.makeText(getApplicationContext(),fail,Toast.LENGTH_SHORT);
           toastcenter.setGravity(Gravity.CENTER,0,0);
           toastcenter.show();

        }
    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {
        super.onPointerCaptureChanged(hasCapture);
    }
}